<template>
  <div class="container">
    <!-- 判断数据请求已经返回再显示 -->
    <div class="content">
      <div v-if="types === 0">
        <!-- 显示用户数据 -->
        <div class="user" v-if="userdataArr.length !== 0">
          <h4 class="title">用户:</h4>
          <!-- 循环渲染用户数据 -->
          <div class="containers" v-for="item in userdataArr" :key="item.id">
            <div class="headerimg">
              <!-- 有头像则显示 -->
              <img :src="item.user_pic" v-if="item.user_pic" />
              <div class="anonymity" v-else>匿名</div>
            </div>
            <div class="contents">
              <!-- 详细个人消息 -->
              <div class="userinfo">
                <h3>{{item.nickname?item.nickname:'匿名' }}</h3>
                <p class="timer">简介 {{item.intro?item.intro:'?'}}</p>
                <p class="timer">
                  来自
                  <a>{{item.from?item.from:'?'}}</a>
                </p>
              </div>
            </div>
            <div class="visit">
              <span @click="visithome(item)">访问主页></span>
            </div>
          </div>
        </div>
        <!-- 显示文章数据 -->
        <div class="walls" v-if="wallsdataArr.length !== 0">
          <h4 class="title">文章墙:</h4>
          <Works :worksData="wallsdataArr"></Works>
        </div>
        <!-- 都没有数据展示 -->
        <div v-if="userdataArr.length === 0 && wallsdataArr.length === 0">抱歉！无法根据当前关键字获取到结果</div>
      </div>
      <div v-else-if="types === 1">
        <!-- 显示用户数据 -->
        <div class="user" v-if="userdataArr.length !== 0">
          <h4 class="title">用户:</h4>
          <!-- 循环渲染用户数据 -->
          <div class="containers" v-for="item in userdataArr" :key="item.id">
            <div class="headerimg">
              <!-- 有头像则显示 -->
              <img :src="item.user_pic" v-if="item.user_pic" />
              <div class="anonymity" v-else>匿名</div>
            </div>
            <div class="contents">
              <!-- 详细个人消息 -->
              <div class="userinfo">
                <h3>{{item.nickname?item.nickname:'匿名' }}</h3>
                <p class="timer">简介 {{item.intro?item.intro:'?'}}</p>
                <p class="timer">
                  来自
                  <a>{{item.from?item.from:'?'}}</a>
                </p>
              </div>
            </div>
            <div class="visit">
              <span>访问主页></span>
            </div>
          </div>
        </div>
        <div v-if="userdataArr.length === 0">抱歉！没有根据关键字匹配到用户</div>
      </div>
      <div v-else-if="types === 2">
        <!-- 显示文章数据 -->
        <div class="walls" v-if="wallsdataArr.length !== 0">
          <h4 class="title">文章墙:</h4>
          <Works :worksData="wallsdataArr"></Works>
        </div>
        <div v-if="wallsdataArr.length === 0">抱歉！没有根据关键字匹配到文章</div>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from "dayjs";
// 引入文章模板组件
import Works from "@/views/works/index.vue";
export default {
  props: ["wallsdataArr", "types", "userdataArr"],
  data() {
    return {};
  },
  methods: {
    visithome() {
      // 跳转到主页
      this.$router.push({
        name: "/mine",
        params: { uuId: item.uuId },
      });
    },
  },
  components: {
    Works,
  },
  computed: {
    // 解决mysql返回值带z带t问题
    timer() {
      return (timer) => {
        return dayjs(timer).format("YYYY-MM-DD HH:mm:ss");
      };
    },
  },
};
</script>

<style lang="less" scoped>
h4 {
  color: #008c8c;
  font-weight: 700;
}
.containers {
  display: flex;
  justify-content: start;
  padding: 10px 0;
  min-width: 718px;
  border-bottom: 1px solid #008c8c;
  .headerimg {
    width: 50px;
    height: 50px;
    padding-right: 10px;
    img {
      margin-top: 5px;
      border-radius: 50%;
      width: 100%;
      height: 100%;
      cursor: pointer;
    }
    .anonymity {
      width: 50px;
      height: 50px;
      line-height: 50px;
      text-align: center;
      border-radius: 50%;
      background: #8590a6;
      color: #fff;
      font-size: 18px;
      font-weight: 700;
      margin-right: 10px;
    }
  }
  .contents {
    width: 578px;
    .userinfo {
      h3 {
        font-size: 16px;
        font-weight: 700;
        cursor: pointer;
      }
      h3:hover {
        color: #008c8c;
      }
      .timer {
        font-size: 12px;
        color: #008c8c;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }
    }
  }
  .visit {
    width: 80px;
    height: 60px;
    line-height: 60px;
    font-size: 12px;
    color: #008c8c;
    span {
      cursor: pointer;
    }
  }
}
</style>